<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	include(ROOTPATH .'include'. DS .'checkUserLogin.php');
	include ROOTPATH .'include'. DS .'isMyQuery.php';
	
	$faceUrl			= getQuery('faceUrl');
	$description 		= getQuery('description');
	
	$faceUrl			= explode('|',$faceUrl);
	
	
	//  移动 + 检测验证合法性
	$faceBig			= $faceUrl[0] ;
	$faceSmall			= $faceUrl[1] ;	
	//$faceBig 			= moveUploadFile($faceBig, USERFACE_BIG_PATH );
	//$faceSmall 		= moveUploadFile($faceSmall, USERFACE );
	
	
	
	$root_path_count = strlen(ROOT_PATH);
	if( substr( $faceBig ,0, $root_path_count) == ROOT_PATH ){
		$faceBig = substr( $faceBig , $root_path_count) ;
		$faceSmall = substr( $faceSmall , $root_path_count) ;
	}
	
	$tmp_path = str_replace(DS,'',TMP_PATH);
	
	if( substr( $faceBig ,0,strlen($tmp_path)) == $tmp_path ){	
	
		// 不信任客户端，重新裁剪
		$userUploadPhoto = new userUploadPhoto ;
		$saveName = substr(md5(md5($user -> id()  )),8,24) ;
		
		
		$savePath = USERFACE_BIG_PATH;// . creatFolder(USERFACE_BIG_PATH);	
		$faceBig = $userUploadPhoto -> cropUserPhoto($faceBig, $savePath , $saveName , USERFACE_BIG_WIDTH , USERFACE_BIG_HEIGHT  );
		
		$savePath = USERFACE_PATH ;//. creatFolder(USERFACE);	
		$faceSmall = $userUploadPhoto -> cropUserPhoto($faceSmall, $savePath , $saveName , USERFACE_SMALL_WIDTH , USERFACE_SMALL_HEIGHT  );			
		
		$array['faceBig']		= $faceBig;
		$array['faceSmall']		= $faceSmall;
	}
	
	
	
	
	
	$array['description'] 	= subString( $description , 1000 );
	
	
	$dbs -> update( DB_PRE .'user',$array , ' `id` = '. $user -> id() );	
	exit('{"status":"ok","msg":"'.lang_save_success.'.","url":"'.urlRewrite('option=home&id='. $user -> id()).'"}');
?>